﻿using log4net;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YJYpublicClass
{
    public class LogHelper
    {
        /// <summary>
        /// 日志库引用的实例
        /// </summary>
        private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        /// <summary>
        /// 日志委托实例
        /// </summary>
        public static Action<string, int> logEvent;
        /// <summary>
        /// 正常日志
        /// </summary>
        /// <param name="str">显示内容</param>
        public static void Info(string str)
        {
            string LogTime = System.DateTime.Now.ToString("HH:mm:ss");
            string LogMessage = LogTime + ":" + str + "\r\n";
            logger.Info(LogMessage);
            logEvent?.Invoke(LogMessage, 0);
        }
        /// <summary>
        /// 警告类型的日志
        /// </summary>
        /// <param name="str">警告内容</param>
        public static void Warn(string str)
        {
            string LogTime = System.DateTime.Now.ToString("HH:mm:ss");
            string LogMessage = LogTime + ":" + str + "\r\n";
            logger.Warn(LogMessage);
            logEvent?.Invoke(LogMessage, 1);
        }
        /// <summary>
        /// 错误类型的日志
        /// </summary>
        /// <param name="str">要表达的错误类型</param>
        /// <param name="ex">异常</param>
        public static void Error(string str, Exception ex)
        {
            string LogTime = System.DateTime.Now.ToString("HH:mm:ss");
            string LogMessage = LogTime + ":" + str + "\r\n";
            logger.Info("异常:"+LogMessage);
            logEvent?.Invoke("异常:"+LogMessage, 2);
        }
        /// <summary>
        /// 错误类型的日志
        /// </summary>
        /// <param name="str">要表达的错误类型</param>
        /// <param name="ex">异常</param>
        public static void Error(string str)
        {
            logger.Info("异常:");
            logEvent?.Invoke(str, 2);
        }
    }
}

